#include "mainDialog.h"

mainDialog::mainDialog(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
	this->resize(900, 600);
	this->setMinimumSize(900, 600);
	this->setWindowIcon(QIcon(":/mainSouces/images/Qicon.jpg"));
	this->setWindowTitle("小九的视频会议主界面");
	ui.mainStackedWidget->setCurrentIndex(0);
	ui.videoStackedWidget->setCurrentIndex(0);
	setReserveTable();//预定会议界面初始化
	setMyMeetTable();//我的会议界面初始化
}

mainDialog::~mainDialog()
{}

void mainDialog::setReserveTable()
{
	//初始化默认会议主题
	ui.subjectLineEdit->setText("小九的预定会议");
	//初始化默认开始时间
	QDateTime nowDateTime = QDateTime::currentDateTime();
	QString strNowDateTime = nowDateTime.toString("yyyy-MM-dd hh:mm:ss");//2025-03-13 22:24:09
	QString strNowDate = strNowDateTime.mid(0, 10);
	QString strNowTime = strNowDateTime.mid(11, 8);
	QDate initDate = QDate::fromString(strNowDate,"yyyy-MM-dd");
	ui.startDateEdit->setDate(initDate);
	ui.startDateEdit->setMinimumDate(initDate);
	QTime initTime = QTime::fromString(strNowTime);
	ui.startTimeEdit->setTime(initTime);
	ui.startTimeEdit->setMinimumTime(initTime);
	//注入持续时长数据
	for (int i = 0; i < 24; i++)
	{
		QString strDuring = QString("%1小时").arg(i);
		if (strDuring == "0小时")
		{
			strDuring = "30分钟";
			ui.durComboBox->addItem(strDuring);
			continue;
		}
		ui.durComboBox->addItem(strDuring);
		strDuring.append("30分钟");
		ui.durComboBox->addItem(strDuring);
	}
	//QStringList strDuring = { "30分钟", "1小时","1小时30分钟","2小时" };
	//ui.durComboBox->addItems(strDuring);
	//周期性数据
	QString strCycleItem = QString("不重复,每天,每周(周%1),每月").arg(initDate.dayOfWeek());
	ui.cycleComboBox->addItems(strCycleItem.split(","));
	QObject::connect(ui.cycleComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &mainDialog::slots_cycleBox_change);
	//结束控件
	ui.endComboBox->addItems({ "某天","限定会议次数" });
	QObject::connect(ui.endComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &mainDialog::slots_endBox_change);
	ui.label_9->setVisible(false);
	ui.endComboBox->setVisible(false);
	ui.endDateEdit->setVisible(false);
	ui.label_9->setHidden(true);
	ui.endComboBox->setHidden(true);
	ui.endDateEdit->setHidden(true);
	ui.timesLineEdit->setVisible(false);
	ui.timesLineEdit->setValidator(new QRegExpValidator(QRegExp("[0-9]{11}")));
	ui.timesLineEdit->setText("1");
	return;
}

void mainDialog::setMyMeetTable()
{
	//QString strSubject = "strSubject";
	//QString strNumber = "strNumber";
	//QString strDate = "strDate";
	//QString strOwner = "strOwner";
	//for (int i = 0; i < 10; i++)
	//{
	//	QListWidgetItem *item = new QListWidgetItem();
	//	item->setSizeHint(QSize(200, 150));
	//	myListWidget *myItem = new myListWidget();
	//	myItem->getListInfo(strSubject, strNumber, strDate, strOwner);
	//	ui.listWidget->addItem(item);
	//	ui.listWidget->setItemWidget(item, myItem);
	//}
	LocalListWidget *widget = new LocalListWidget();
	LocalItem item;
	item.id = 0;
	item.bCycle = false;
	item.strSubject = "strSubject";
	item.strNumber = "strNumber";
	item.strDate = "strDate";
	item.strOwner = "strOwner";
	widget->AddItem(item);
}

void mainDialog::on_welcomePushButton_clicked()
{
	ui.mainStackedWidget->setCurrentIndex(0);
}

void mainDialog::on_videoPushButton_clicked()
{
	ui.mainStackedWidget->setCurrentIndex(1);
}

void mainDialog::on_gamePushButton_clicked()
{
	ui.mainStackedWidget->setCurrentIndex(2);
}

void mainDialog::on_joinPushButton_clicked()
{
	ui.videoStackedWidget->setCurrentIndex(0);
}

void mainDialog::on_reservePushButton_clicked()
{
	ui.videoStackedWidget->setCurrentIndex(1);
}

void mainDialog::on_historyPushButton_clicked()
{
	ui.videoStackedWidget->setCurrentIndex(2);
}

void mainDialog::on_myPushButton_clicked()
{
	ui.videoStackedWidget->setCurrentIndex(3);
}

void mainDialog::slots_cycleBox_change(int i)
{
	if (i == 0)
	{
		ui.label_9->setVisible(false);
		ui.endComboBox->setVisible(false);
		ui.endDateEdit->setVisible(false);
		ui.label_9->setHidden(true);
		ui.endComboBox->setHidden(true);
		ui.endDateEdit->setHidden(true);
		ui.timesLineEdit->setVisible(false);
	}
	else
	{
		ui.label_9->setVisible(true);
		ui.endComboBox->setVisible(true);
		ui.endDateEdit->setVisible(true);
		ui.label_9->setHidden(false);
		ui.endComboBox->setHidden(false);
		ui.endDateEdit->setHidden(false);
		ui.endComboBox->setCurrentIndex(0);
	}
}

void mainDialog::slots_endBox_change(int i)
{
	if (i == 0)
	{
		ui.endDateEdit->setVisible(true);
		ui.timesLineEdit->setVisible(false);
	}
	else
	{
		ui.endDateEdit->setVisible(false);
		ui.timesLineEdit->setVisible(true);
		QPoint point = ui.endComboBox->pos();
		ui.endComboBox->resize(120, 25);
		ui.timesLineEdit->resize(80, 25);
		ui.timesLineEdit->move(point.x() + 120, point.y());
	}
	return;
}
